<template>
	<view class="billdetails" id="billdetails">
		<view class="billdetails_top">
			<view class="name">{{name}}{{address}}</view>
			<view class="moeny">{{Number(billList.order.money).toFixed(2)}}</view>
			<view class="last">{{billList.order.status==1?'待缴费':billList.order.status==3?'已退款':'已缴费'}}</view>
		</view>
		<!-- 分割线 -->
		<view class="xian ">
			<view class="xian_left"></view>
			<view class="xian_center"></view>
			<view class="xian_right"></view>
		</view>
		<!-- 主体内容 -->
		<view class="main">
			<view class="main_jh">
				<view class="zdbh clearfix">
					<view class="bh">账单编号</view>
					<view class="num">{{billList.order.code}}</view>
				</view>
			</view>
			<view class="main_jh">
				<view class="zdbh clearfix">
					<view class="bh">缴费时间</view>
					<view class="num">{{billList.order.createTime}}</view>
				</view>
			</view>
			<view class="main_jh">
				<view class="zdbh clearfix">
					<view class="bh">
						缴费名称
					</view>
					<view class="num">{{billList.order.name}}</view>
				</view>
			</view>
			<view class="bill-deta-btn" v-show="billList.order.status==1">
				<button @click="payClick"  class="yilingqu">微信缴费</button>
			</view>
			<view class="bill-deta-btn alipay" v-show="billList.order.status==1">
				<button @click="requestPayment"   class="yilingqu">支付宝缴费</button>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				allmoney: '3600.00',
				type: '已支付',
				num: 'WY20200807',
				billList: {},
				homelist: '',
				name: '',
				address: '',
				money: '',
				chooseList: [],
				
				//支付宝支付
				title:'request-payment',
				loading:false,
				price:1,
				providerList:[],
				userObj:{},
			}
		},
		// onLoad(options) {
		// 	const item = JSON.parse(decodeURIComponent(options.item))
		// 	this.userObj =item
		// 	console.log(this.userObj)
		// },
		onShow() {
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
			this.name = this.homelist.proName;
			this.address = this.homelist.buildDistrictCode + '-' + this.homelist.buildTowerCode + '-' + this.homelist
							.roomUnitNumber +
					'-' + this.homelist.roomCode
			this.money = this.$Route.query.money
			this.chooseList = this.$Route.query.chooseList
			this.getBillDetail()

		},
		methods: {
			// //是否跳转开发票页面
			// navTo(url) {
			// 	let items = encodeURIComponent(JSON.stringify(this.userObj))
			// 	uni.navigateTo({
			// 		url: url + '?item='+ items
			// 	});
			
			// },
			async getBillDetail() {
				let res = await this.$request.api.billDetails({
					setId: this.homelist.setId,
					id: this.$Route.query.id,
					mobile: uni.getStorageSync('phone')
				})
				console.log(res)
				this.billList = res.data.data
				console.log(this.billList)
			},
			
			//支付宝支付
			requestPayment(){
				// 打开支付宝里面的搜索：  alipayqr://platformapi/startapp?saId=20001003
				// 支付宝收款码:   alipayqr://platformapi/startapp?saId=20000123
				// 支付宝扫一扫：alipayqr://platformapi/startapp?saId=10000007
				// 支付宝付款：alipay://platformapi/startapp?appId=20000056
				//let authUrl = `alipays://platformapi/startapp?appId=20000067&url=HTTPS%3a%2f%2fQR.ALIPAY.COM%2fFKX09099VQZDCJ1QFGXA9F`;
				//let authUrl = `alipays://platformapi/startapp?appId=2021002127637334&url=${encodeURIComponent('345%^4567657path:009')}`;
				//const query = encodeURIComponent('要带的参数')
				//plus.runtime.openURL("alipays://platformapi/startapp?appId=要跳转的支付宝小程序appid&要跳转的页面" + 要带的参数);
				//const URL = encodeURIComponent('https://www.515f.com/adapay?key=WY2022031919171531&money=0.30&proId=54')
				const order = this.billList.order.code;//订单编号
				const money = this.billList.order.money; //金额
				const proId = this.billList.order.proId;
				const URL = encodeURIComponent(`https://www.515f.com/adapay?key=${order}&money=${money}&proId=${proId}`);
				let authUrl = `alipays://platformapi/startapp?saId=10000007&qrcode=`+URL;
				//console.log(authUrl);
				plus.runtime.openURL(authUrl, function (res) {
					uni.showToast({
						icon: "none",
						title: "请安装支付宝之后再进行支付！",
					});
				});
			},
			async requestPayment1(e,index){
				//let orderInfo = await this.getOrderInfo();
				//console.log(orderInfo,'--得到订单信息')
				//console.log('显示订单信息--orderInfo---',JSON.stringify(orderInfo))
				uni.requestPayment({
				    provider: 'alipay',
				    orderInfo: 'appId=2021002127637334',//orderInfo, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
				    success: function (res) {
							uni.showToast({
								title:'感谢您的支持'
							})
				        console.log('success:' + JSON.stringify(res));
				    },
				    fail: function (err) {
							uni.showModal({
								content:'支付失败,原因为：'+err.errMsg
							})
				        console.log('fail:' + JSON.stringify(err));
				    },
						// complete:()=> {
						// 	this.providerList[index].loading = false;
						// }
				});
			},
			getOrderInfo(){
				let appid = '';
				//#ifdef APP-PLUS
				  appid = plus.runtime.appid;
				//#endif 
				let url = 'https://dmin.515f.com/getOrderInfo'
				return new Promise((res) =>{
					uni.request({
						url:url,
						success(result) {
							res(result)
						},
						fail(e) {
							res(e)
						}
					})
				})
			},
			priceChange(e){
				this.price = e.detail.value;
			},
			async payClick() {
				let data = {
					id: this.$Route.query.id,
					mobile: uni.getStorageSync('phone'),
					proId: this.homelist.proId,
					money: Number(this.money).toFixed(2),
					code: this.billList.order.code,
					name: this.name,
					address: this.address,
					setId: this.homelist.setId,
					childList:this.billList.childList,
					billList: this.billList,
					source:'APP001',
					wysfAPP:'1',
					//orderObj:this.billList.order
				}
				console.log(this.billList.order,'===跳转小程序之前参数')
				let str = JSON.stringify(data)
				// 小程序跳转
				plus.share.getServices(
						res => {
							let sweixin = null;
							for (let i in res) {
								if (res[i].id == 'weixin') {
									sweixin = res[i];
									console.log(sweixin,'------sweixin')
								}
							}
							//唤醒微信小程序
							if (sweixin) {
								sweixin.launchMiniProgram({
									id: 'gh_356131c8d206', //
									type:0, //小程序版本  0-正式版； 1-测试版； 2-体验版。
									path: '/homePage1/billdetails/billdetails?data='+str//小程序的页面,用传的参数在小程序接值判断跳转
								});
							}
						}
				);
			}
		}
	}
</script>

<style scoped lang="scss" scoped>
	#billdetails{
	.billdetails {
		padding: 0 30rpx;
	}
	.billdetails_top {
		height: 312rpx;
		text-align: center;
		background-color: #fff;
		margin-top: 60rpx;
		border-top-left-radius: 6px;
		border-top-right-radius: 6px;

		.name {
			padding-top: 60rpx;
			box-sizing: border-box;
			font-size: 36rpx;
			font-weight: 550;

		}
		.last {
			margin-top: 20rpx;
			color: rgb(128, 229, 255);
		}
		.moeny {
			font-size: 48rpx;
			color: #000;
			font-weight: bold;
			margin-top: 48rpx;
		}
	}

	.xian {
		height: 50rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;

		.xian_center {
			height: 1px;
			border-top: 1px dashed #ccc;
			margin: 25rpx 40rpx;
			width: 600rpx;

		}
		.xian_left {
			width: 50rpx;
			height: 50rpx;
			border-radius: 50%;
			float: left;
			background-color: rgb(244, 244, 244);
			margin-left: -7vw;
		}
		.xian_right {
			width: 50rpx;
			height: 50rpx;
			border-radius: 50%;
			float: right;
			background-color: rgb(244, 244, 244);
			margin-right: -7vw;

		}
	}
	.zdbh {
		margin-bottom: 30rpx;
		.bh {
			float: left;
		}
		.num {
			float: right;
		}
	}
	.wyf {
		.wyfname {
			float: left;
		}
		.wyfmoney {
			float: right;
		}
		.view {
			margin-bottom: 30rpx;
		}
	}
	.main_jh {
		margin-bottom: 60rpx;
	}
	.main {
		background-color: #fff;
		padding: 60rpx 42rpx;
	}
	.bill-deta-btn {
		width: 100%;
		.pay{
			background: #ff9900 !important;
			color: #fff;
		}
		.yilingqu{
			width: 80%;
			height: 84rpx;
			// background:#F9A832;
			// background-color: #F9A832;
			background: linear-gradient(180deg, #76D904 0%,#417505 100%);
			border-radius: 44rpx;
			line-height: 84rpx;
			color: #FFFFFF;
			text-align: center;
			font-size: 32rpx;
		}
	}
	.alipay{
		margin-top: 50rpx;
	}
}
</style>
